use std::fs;

pub(crate) struct Config<'a> {
    path: &'a str,
    pub version: String,
}

impl<'a> Config<'a> {
    pub fn new(path: &str) -> Config {
        let config = fs::read_to_string(path)
            .unwrap_or_else(|_| {
                fs::write(path, "1.3.0").unwrap();
                "1.3.0".to_string()
            });

        Config {
            path,
            version: config.trim().to_string(),
        }
    }

    pub fn write(&self, ver: &str) {
        fs::write(self.path, ver).unwrap();
    }
}

